#include<iostream>
using namespace std;
#include<vector>
#include <queue>

class KthLargest {
public:
    int _k = 0;
    priority_queue<int,vector<int>,greater<int>> _nums;

    KthLargest(int k, vector<int>& nums) {
        _k = k;
        int lengthNums = nums.size();
        for (int i = 0; i < lengthNums; i++)
        {
            if (_k)
            {
                _nums.push(nums[i]);
            }
            else
            {
                _nums.push(nums[i]);
                _nums.pop();
            }
        }
    }


    int add(int val) {

        if (_k)
        {
            _nums.push(val);
        }
        else
        {
            _nums.push(val);
            _nums.pop();
        }
        return _nums.top();
    }
};

int main()
{
    vector<int> nums = { 4, 5, 8, 2 };

    KthLargest k(3, nums);
    k.add(3);
    k.add(100);
	return 0;
}